<template>




</template>
<script>
    import * as type from '../../store/types';
    import vBillcomp from '../common/BillComp.vue';
    import Waterfall from '../common/waterfall/Waterfall.vue';
    import WaterfallSlot from '../common/waterfall/waterfall-slot';
    export default {
        name: "keepaliveactiveinfo",
        components: {
            vBillcomp, Waterfall, WaterfallSlot
        },
        props:{
            isUpdate:'',
            tabText1:'',
            tabText2:'',
            activate:'',
            changeActivited:'',
            backItems:{
                type:Function,
                default:function(){},
                required:false
            },
            routerItem:'',
            isBackGoods:'',
            url:'',
            saveUrl:'',
            delUrl:''
        },
        data: function () {
            return {
                activeName:'first',
                loading: true,
                items: [],
                imageUrl: '',
                Actid: '',
                static_url: this.$cfg.static_url + "/",
//                uploadUrl:this.$cfg.api_url+"/vue-uploads",
                userId: '',
                formInfo: {},
                formInfoRules: {
                    name: [
                        {required: true, message: '请输入活动名称', trigger: 'change'}
                    ],
                    price: [
                        {required: true, pattern: /^[0-9.]*$/, message: '活动单价为必填项且必须为数字', trigger: 'change'},

                    ],
                    code: [
                        {pattern: /^[0-9a-zA-Z]*$/, message: '活动编码只能为数字和字母', trigger: 'change'}
                    ]
                },
                hasPic:true,
                actItem: '',
                status: false,
                state: '',
                open: false,
                list: [],
                num: [0],
                changeSure: [],
                isSecond: true,
                isGoods: true,
                selectItems: [],
                currentRadio: {index:-1},
                isMutpart:false,
                page: 1,
                totalPage: 1,
                quantity:0,
                selectGoods:'',
                delClose:true,
                selectDel:'',
                delClose:true,
            }
        },
        watch: {
            param(val){
                this.items = [];
                this.page = 1;
                this.totalPage = 1;
                this.loadMore();
            },

            loadmoreinfo(){
                //alert(3)
            },
            changeActiviteds:function () {

            }
        },
        computed:{
          loadmoreinfo:function () {
                this.activeName = "second";
                let a   = this.isUpdate.flag;
                this.page = 1;
                this.totalPage = 1;
                if(a) {
                    this.loadMore();
                    this.isUpdate.flag = false;
                }
          },
          changeActiviteds:function(){
              let cactivited  = this.changeActivited.name;
              this.activeName = 'first';
          }
        },
        mounted: function () {
            this.actItem='';
            this.num=[];
            this.delClose = true;
            console.log("=============>mounted")
            let self = this;
            console.log(this.$$("#content").innerHeight())
            console.log(this.$$("#content")[0].scrollWidth)
            this.rows = Math.floor(self.$$("#content")[0].scrollWidth / 300) * Math.floor(self.$$("#content").innerHeight() / 220)
            console.log('*(******************' + this.rows)
            this.$$("#content").on('scroll', function (e) {
                var scrollTop = self.$$("#content").scrollTop();
                var innerHeight = self.$$("#content").innerHeight();
                var scrollHeight = self.$$("#content").scrollHeight();
                if (scrollTop + innerHeight >= scrollHeight) {
                    self.page++;
                    self.loadMore();
                    console.log('*(******************' + self.page)
                }
            })

        },
        methods: {

            loadMore() {
                console.log("==============>loadMore")
                console.log(this.totalPage)
                if (this.page <= this.totalPage) {
                    this.loading = true;
                    this.Actid = this.routerItem.id;
                    var url=this.url;
                    let self = this;
                    this.$axioxs.get(url)
                        .then(function (res) {
                            self.totalPage = res.data.totalPage;
                            console.log(res.data)
                            if(res.data.records){
                                self.actItem = res.data.records;
                            }else{
                                self.actItem = res.data;
                            }


                            self.actItem.forEach(item => {
                                item.height = 265;
                                item.width = 300;
                                self.items.push(item);
                            });
                            self.loading = false;
                        })
                        .catch(function (error) {
                            console.log(error);
                            self.$message({
                                showClose: true,
                                type: 'error',
                                message: error,
                                onClose: function () {
                                    self.loading = false;
                                }
                            });
                        });
                }
            },
            handleClick(tab, event) {
                if (this.activeName == 'first') {

                    this.isSecond = true;
                    this.backItems(this.isSecond);
                } else if (this.activeName == 'second') {
                    this.$$(window).resize();
                    this.isSecond = false;
                    this.totalPage=1;
                    this.loadMore();
                    this.backItems(this.isSecond);
                }
            },
            del: function (item) {
                console.log(111111)
                var saveUrl=this.saveUrl+item.id;
                let self = this;
                this.$axioxs.delete(saveUrl)
                    .then(function (res) {
                            console.log('删除成功')
                            self.$message({
                                showClose: true,
                                message: '删除成功',
                                type: 'success'
                            });
                            self.actItem.splice(self.actItem.indexOf(item), 1)
                            self.activeName = "second";
                        },
                        (res) => {
                            this.$message({
                                showClose: true,
                                type: 'error',
                                message: res
                            });
                        });
            },
            changeNum: function (index, item, changeSure, toSure) {
                this.$set(this.changeSure, index, true);
//                this.$set(this.toSure, index, false);
                this.num[index] = item.quantity;
            },
            getCurrentSelectItems: function (items) {
                console.log("==================>")
                console.log(items)
                this.selectDel = items;
            },
            saveNum: function (index, item, changeSure, toSure) {

                this.$set(this.changeSure, index, false);
                var quantity = this.num[index];
                let args = {
                    goodId: item.goods.id,
                    goodName: item.goods.name,
                    goods: {
                        id: item.goods.id
                    },
                    id: item.id,
                    owner: {
                        id: this.$route.params.item.id
                    },
                    price: item.price,
                    quantity: item.quantity,
                    ver: item.ver

                };
                var saveUrl=this.saveUrl;
                let self = this;
                console.log(args)
                if(quantity!=item.quantity ){
                    this.$axioxs.post(saveUrl, args)
                        .then(function (res) {
                                self.loadMore();
                            },
                            (res) => {
                                this.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: res
                                });
                            }
                        )
                }

            },
            toChange: function () {
                var item = this.routerItem;
                console.log(1111111111111111)
                console.log(item)
                this.$store.commit(type.CHANGE_INDEX, '/goodsComp');
                this.$router.push({
                    name: 'goodsB',
                    path: '/goodsComp',
                    params: {
                        'url': "/goods/?states=1",
                        'saveurl': "/goods_package/entry/",
                        'backurl': "/activityInfo",
                        'activeName': "second",
                        'item':item,
                        'backName': 'activityA'
                    },
                });
            },
        }
    }
</script>
<style scoped>
    .close-del {
        width: 30px;
        height: 30px;
        line-height: 30px;
        text-align: center;
    }

    .close-fa-circle {
        font-size: 1.25em;
    }
    .member-info-title {
        padding-top: 60px;
    }

    .member-info-form {
        width: 90%;
        padding-top: 0px;
        margin: 0 auto;
    }

    .img {
        width: 80px;
        height: 80px;
        margin: 10px auto;
    }
    .item {
        position: absolute;
        top: 5px;
        left: 5px;
        right: 5px;
        bottom: 5px;
        font-size: 1.2em;
        color: rgb(0, 158, 107);
    }
    .w-user {
        margin: 0px 20px;
    }


    .text {
        margin-bottom: 1em;
    }

    .text h6 {
        margin-bottom: 5px;
    }

    .span1 {
        background-color: #3eb3f9;
        border-radius: 20px;
        padding: 2px 5px;
        color: #fff !important;
        font-size: .8em;
        margin-right: 3px;
    }

    .span2 {
        background-color: #6699ff;
        border-radius: 20px;
        padding: 2px 5px;
        color: #fff !important;
        font-size: .8em;
        margin-right: 3px;
    }

    .remark {
        padding: 3px 0;
    }
    .text-number{
        width: 60%;
        height: 27px;
        border: 1px solid #cacaca;
        border-radius: 3px;
    }
    .text-numspan{
        display: block;
    }
    .quantity-h{
        height:30px;
        line-height: 30px;
    }
    .card-storage{
        height:220px;
        padding: 4em 0!important;
    }
</style>
